package carassius.GUI;

import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author siebz0r
 */
public class DoubleTableCellRenderer extends DefaultTableCellRenderer
{
	private final DoubleLabel DOUBLE_LABEL;

	public DoubleTableCellRenderer()
	{
		DOUBLE_LABEL = new DoubleLabel();
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
												   boolean isSelected,
												   boolean hasFocus, int row,
												   int column)
	{
		DOUBLE_LABEL.setValue((value instanceof Double) ? (Double) value : null);
		return super.getTableCellRendererComponent(table, DOUBLE_LABEL.getValue(), isSelected, hasFocus, row, column);
	}

	public boolean isValueValid()
	{
		return DOUBLE_LABEL.textIsValid();
	}
}
